package priv.yiyuan.example.design.facade;

/**
 * 文档转换外观类
 * <p>
 * 外观模式-外观类
 * 策略模式-上下文
 *
 * @author YiYuan
 * @data 2025/9/12
 * @apoNote
 */
public class DocumentConverterFacade {

    private DocumentConversionStrategy strategy;

    public void setConversionStrategy(String fileType) {
        switch (fileType.toLowerCase()) {
            case "docx":
                this.strategy = new WordToHtmlStrategy();
                break;
            case "xlsx":
                this.strategy = new ExcelToHtmlStrategy();
                break;
            case "pdf":
                this.strategy = new PdfToHtmlStrategy();
                break;
            default:
                throw new IllegalArgumentException("不支持的文档类型: " + fileType);
        }
    }

    public String convertDocumentToHtml(String filePath, String fileType) {
        System.out.println("\n--- 开始转换文档 ---");
        this.setConversionStrategy(fileType);
        if (this.strategy == null) {
            throw new IllegalStateException("未设置转换策略。");
        }

        String htmlContent = this.strategy.convert(filePath);
        System.out.println("\n--- 文档转换完成 ---");
        return htmlContent;
    }

}
